var tt=null;
var aa;
var n=0;
var timer=0;
window.onload=function(){//登录执行
  var li=document.getElementById("btn").getElementsByTagName("li");//获取li
  aa=document.getElementById("imm").getElementsByTagName("a");
  for(var i=0;i<aa.length;i++){//遍历a
    if(i!=0){
      aa[i].style.opacity=0;//透明度0
    }
  }
  for(var j=0;j<li.length;j++){//遍历li
      li[j].onmouseover=function(){//鼠标进入
        var that=this;//记录当前this指向
        tt=setTimeout(function()
        { 
          var index=that.innerHTML-1;
          n=index;
          if(index <aa.length){
            for(var o=0;o<li.length;o++){
              li[o].className="";//li的class名置空
              aa[o].style.opacity=0;
              aa[o].style.zIndex=9998;
            }
            that.className="on";
            aa[index].style.opacity=1;
            aa[index].style.zIndex=9999;
            aa[index].style.transition="opacity 0.8s";
             leftf(-300,0,aa[index]);
          }
        },100);

      };
    li[j].onmouseout=function(){
      clearTimeout(tt)
    }
    }

  var left=document.getElementById("left");
  var right=document.getElementById("right");
  var body=document.getElementById("cont");

  timer = setInterval("autoplay()",2000);//设置定时器，自动轮播
  body.onmouseover=function(){//鼠标移入body定时器清空，轮播图停止轮播
    clearInterval(timer);
  };
  body.onmouseout=function(){//移入开始定时器，开始自动轮播
    timer = setInterval("autoplay()",2000);
  };

  left.onclick=function(){//点击左边按钮
    if(n>0){
      n--
    }else if(n==0){
      n=aa.length-1;
    }
    var li=document.getElementById("btn").getElementsByTagName("li");
    li[n].onmouseover()
  };

  right.onclick=function(){//右边按钮
    n=n>=(aa.length-1)?0:++n;
    var li=document.getElementById("btn").getElementsByTagName("li");
    li[n].onmouseover()
  }
}
function leftf(start,end,ele){ //移动
  var tt=setInterval(function (){//移动定时器
  start+=30;//每次加30
  ele.style.right=start+"px";//设置样式
  if(start==end){//开始=结束清空定时器
    clearInterval(tt)
  }
      },30)
}

function autoplay(){
  n=n>=(aa.length-1)?0:++n;
  var li=document.getElementById("btn").getElementsByTagName("li");
  li[n].onmouseover()
};